﻿
@{
    ViewBag.Title = "新增编辑菜单";
}
@section css{
    <link href="~/js/treeSelect/treeselect.css" rel="stylesheet" />
}
<div class="layui-form-item">
    <label class="layui-form-label">菜单名称</label>
    <div class="layui-input-block">
        <input type="text" name="FullName" class="layui-input" lay-verify="required" placeholder="请输入菜单名称">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">菜单编码</label>
    <div class="layui-input-block">
        <input type="text" name="EnCode" class="layui-input" lay-verify="required" placeholder="请输入菜单编码">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">上级</label>
    <div class="layui-input-block">
        <input type="text" name="ParentId" autocomplete="off" id="ParentId" class="layui-input" lay-verify="required" placeholder="请选择上级菜单">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">目标</label>
    <div class="layui-input-block">
        <select name="Target">
            <option value="">框架页</option>
            <option value="_blank">新页面</option>
        </select>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">菜单链接</label>
    <div class="layui-input-block">
        <input type="text" name="UrlAddress" class="layui-input" placeholder="请输入链接">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">图标</label>
    <div class="layui-input-block">
        <input type="text" name="Icon" class="layui-input" placeholder="请选择图标">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">状态</label>
    <div class="layui-input-block">
        <input type="checkbox" name="EnabledMark" value="1" lay-skin="switch" lay-text="启用|禁用" checked>
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">排序</label>
    <div class="layui-input-block">
        <input type="text" name="SortCode" class="layui-input" lay-verify="required|num" placeholder="请输入排序">
    </div>
</div>
<div class="layui-form-item  layui-form-text">
    <label class="layui-form-label">简介</label>
    <div class="layui-input-block">
        <textarea name="Description" placeholder="请输入简介" class="layui-textarea"></textarea>
    </div>
</div>
<div class="layui-form-item layui-hide">
    <input type="button" lay-submit id="btnSave" lay-filter="SaveMenu" value="确定" />
</div>
@section script{
    <script type="text/javascript">
        layui.use(['form', 'treeselect', 'tools'], function () {
            var $ = layui.$,
                form = layui.form, treeselect = layui.treeselect, tools = layui.tools;

            var key = tools.queryString("key");
            if (key) {
                var parm = [{ url: "/SystemManage/Module/GetForm?key=" + key }, { url: "/SystemManage/Module/GetMenuTree" }];
                tools.requestAll(parm, function (data1, data2) {
                    data1.EnabledMark = data1.EnabledMark ? 1 : 0;
                    form.val("form", data1);
                    initSelect(data2);
                });
            } else {
                //初始化下拉框
                initSelect();
                setTimeout(function () {
                    $("#selecttree_ParentId a").click(function () {
                        let count = $(this).next().children().length;
                        $("[name=SortCode]").val(count + 1);
                    })
                }, 500);
            }

            function initSelect(data) {
                treeselect.render(
                    {
                        elem: "#ParentId",
                        data: data || "/SystemManage/Module/GetMenuTree",
                        method: "get"
                    });
            }
        });
    </script>
}
